package com.meviewer.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.Nullable;

import com.google.common.collect.Lists;

import java.io.IOException;
import java.util.List;

/**
 * @author hanhaoran
 */
public abstract class BaseActivity extends Activity {

    private static final List<BaseActivity> ACTIVITIES = Lists.newArrayList();



    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ACTIVITIES.add(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ACTIVITIES.remove(this);
    }


    public static void restartApp() {
        BaseActivity intent_m =  ACTIVITIES.get(0);
        Intent intent = intent_m.getIntent();
        intent_m.overridePendingTransition(0, 0);
        intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        intent_m.finish();

        intent_m.overridePendingTransition(0, 0);
        intent_m.startActivity(intent);
    }

    public static void exitApp() {
        ACTIVITIES.forEach(BaseActivity::finish);
    }
}
